<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib uri="http://www.longtop.com/intelliweb" prefix="e"%>
<%@page isELIgnored="false"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
		<title>对公客户分配</title>
	</head>
	<e:View id="eView">
		<script language="JScript.Encode" src="<%=request.getContextPath()%>/js/perform/fp_commonQuery.js"></script>	
			
		<div id="Invisual Controls" style="min-height: 40px; background-color: LemonChiffon;">
			<e:Dataset id="Dataset_Cust" pageSize="10" loadDataCommand="cmd_load" allowMultiSelect="false">
				<e:Field name="custId" dataType="string" label="客户号" maxLength="32" />
				<e:Field name="custName" dataType="string" label="客户名称" maxLength="100" ></e:Field>
				<e:Field name="cardType" dataType="string" label="证件类型" maxLength="100" dropDown="ListDropDown__CERT_TYPE"></e:Field>
				<e:Field name="cardNo" dataType="string" label="证件号" maxLength="32" ></e:Field>
				<e:Field name="orgName" dataType="string" label="所属机构" maxLength="100" ></e:Field>
				<e:Field name="orgId" dataType="string" label="所属机构号" maxLength="32" ></e:Field>
				<e:Field name="resId" dataType="string" label="分配状态" maxLength="32" ></e:Field>
			</e:Dataset>
			
			<e:ListDropDown id="ListDropDown__CERT_TYPE" fixed="true" autoDropDown="true">
			</e:ListDropDown>
			
			<e:Command id="cmd_query" action="com.longtop.perform.ar.web.ArDsCustListAction" method="queryCusts" submitForm="true" showHintInfoOnSuccess="false">
				<e:DatasetInfo name="DatasetInfo1" dataset="Dataset_Cust" alwayRefreshClient="true" />
			</e:Command>
			<e:Command id="cmd_load" action="com.longtop.perform.ar.web.ArDsCustListAction" method="loadCusts" submitForm="true" showHintInfoOnSuccess="false" >
			</e:Command>
			<e:ListDropDown id="drop_isAllocate" fixed="true" autoDropDown="true">
				<e:ListDropDownItem name="ListDropDownItem1" label="未分配" value="0"></e:ListDropDownItem>
				<e:ListDropDownItem name="ListDropDownItem2" label="已分配" value="1"></e:ListDropDownItem>
			</e:ListDropDown>
			<e:LookupDropDown id="LookupDropDown_Org" path="/jsp/framework/sys/org/orgDropdown.jsp?isFilter=false"	windowWidth="600" windowHeight="400" 
					autoDropDown="true" fixed="true" onSelect="LookupDropDown_Org_onSelect(dropdown,iframe,text)" windowCaption="选择部门">
			</e:LookupDropDown>
		</div>
	
		<e:Page id="ePage" action="com.longtop.perform.ar.web.ArDsCustListAction" onAfterLoadPage="ePage_onAfterLoadPage()" style="width:100%;height:400px">
			<body>
				<table width="100%" height="100%">
					<tr>
						<td valign="top" style="width: 100% height :90%" align="left">
							<table width="100%" height="100%">
								<tr>
									<td align="left" colspan="2">
										<e:GroupBox id="group_custInfo" style="width: 100%; " caption="对公客户查询">
											<table width="100%" border="0">
												<tr>
													<td align="right">客户号 :</td>
													<td align="left"><e:Text id="T_custId" style="width: 150px;" /></td>
													<td align="right">客户名称 :</td>
													<td align="left"><e:Text id="T_custName" style="width: 150px;" /></td>
													<td></td>
												</tr>
												<tr>
													<td align="right">所属机构 :</td>
													<td align="left">
														<e:Text id="orgId" style="width: 150px;" dropDown="LookupDropDown_Org"/>
													</td>
													<td align="right">证件号码 :</td>
													<td align="left"><e:Text id="T_certNo" style="width: 150px;" /></td>
												</tr>
												<tr>										
													<td align="right">分配状态 :</td>
													<td align="left" colspan="3">
														<e:Text id="T_isAllocate" style="width: 150px;"  dropDown="drop_isAllocate" /></td>
													<td>
															<e:Button id="Button3" caption="查询" style="height: 20px; width: 70px" icon="/images/query.gif" onClick="queryCusts();" />&nbsp; 
															<e:Button id="Button_reset" style="height: 20px; width: 70px" caption="重置" onClick="resetQueryCondition();" icon="/images/refresh.gif"></e:Button> 
															<e:Text id="custType" style="width: 0px;" />
													</td>
												</tr>
											</table>
										</e:GroupBox>
									</td>
								</tr>
								<tr height="30px">
									<td style="height: 30px;" >
										<e:PageNavigator id="PageNavigator_Page" dataset="Dataset_Cust" style="min-width: 200px; height: 25px;" showRecordNum="true" showPageSize="true" ></e:PageNavigator>
									</td>
									<td align="right">
										<e:Button id="Button_apply" caption="事后分配申请" icon="/images/team.gif"  onClick="Button_apply_onClick()" style="width:120px" enabled="1002-02-01-01:1"></e:Button>&nbsp;&nbsp;
										<e:Button id="Button_allocate" caption="分配业绩" icon="/images/addPerson.gif"  onClick="Button_allocate_onClick()" enabled="1002-02-01-01:2"></e:Button>
									</td>
								</tr>
								<tr>
									<td valign="top" align="left" colspan="2">
										<e:Grid id="Grid_result" dataset="Dataset_Cust" readOnly="true" style="width:100%;height:275px;" showIndex="true" allowDragColumn="false" allowResizeColumn="true" showIndicator="false">
											<e:Column name="custId" field="custId"></e:Column>
											<e:Column name="custName" field="custName"></e:Column>
											<e:Column name="cardType" field="cardType"></e:Column>
											<e:Column name="cardNo" field="cardNo"></e:Column>
											<e:Column name="orgId" field="orgId"></e:Column>
											<e:Column name="orgName" field="orgName"></e:Column>
											<e:Column name="isAssign" field="resId" label="分配状态" onRefresh="isAssign_onRefresh(cell,value,record)"></e:Column>								
										</e:Grid>
									</td>
								</tr>
							</table>
						</td>
					</tr>
				</table>
			</body>
		</e:Page>
	</e:View>
	<script type="text/javascript">
		function ePage_onAfterLoadPage(){
			var orgId  = '${sessionScope.sessionObject.orgId}';
			if(${sessionScope.sessionObject.orgLevel} == 3|| (orgId.substring(0,2)=='00' && orgId != '00000')){
				$J("orgId").setValue('${sessionScope.sessionObject.parentOrgId}','${sessionScope.sessionObject.parentOrgName}');
			}
			else{
				$J("orgId").setValue('${sessionScope.sessionObject.orgId}','${sessionScope.sessionObject.orgName}');
			}
		}
	
		//显示分配状态：
		function isAssign_onRefresh(cell,value,record){
			if(value == null || value == ""|| value == "0"){
				cell.innerHTML = "未分配";
			}else{
				cell.innerHTML = "已分配";
			}
		}
		
		//事后申请
		function Button_apply_onClick (){
			var record = $J('Dataset_Cust').getCurrentRecord();
	  		if(record==null){
	  			return;
	  		}
	  		
			var value = record.getValue("resId");
			if(value == null || value == ""|| value == "0"){
			}else{
				MsgBox.showInfoMsg("只能对未分配的业绩进行事后申请。");
				return;
			}
			
			var resId = record.getValue("custId");
	  		var belong = record.getValue("belongOrgCode");
	  		var custId = record.getValue("custId");
	  		var custName = "";
	  		if(record.getValue("custName")!=null&&record.getValue("custName")!=""){
	  			custName =Util.encode(record.getValue("custName"));
	  		}
	  		var urlParas = "?custId=" + custId + "&belong=" + belong+"&custName="+custName+"&resId="+resId+"&arType=CO_CUST";
	  		var url="/jsp/perform/fp/apply/flowFpApplyLaunch.jsp";
			parent.TabUtil.openTab('fpApply', '业绩分配事后申请', url + urlParas, true);					
		}
		
				
		/*查询客户*/
		function queryCusts(){
			cmd_query.execute();
		}
		
		//查询成功后
		function cmd_load_onExecuteSuccess(command){
	   		var dsScript = command.parameters.getValue("dsScript");
			var grid = $J("Grid_result");
			//使用后台传递回来的Dataset的机构,动态的更新Grid的结构
			if (globalEval(dsScript)) {
				grid.setDataset(null);
				grid.rebuild($J("Dataset_Cust"));
				$J("PageNavigator_Page").setDataset($J("Dataset_Cust"));
				$J("PageNavigator_Page").render();				
			}			
		}
		
	  	//分配业绩
	  	function Button_allocate_onClick(){
	  		var record = $J('Dataset_Cust').getCurrentRecord();
	  		if(record==null){
	  			MsgBox.showInfoMsg("请选择你要分配业绩的客户！");
	  			return;
	  		}
	  		var orgId = record.getValue("orgId");
	  		var custId = record.getValue("custId");
	  		var custName = "";
	  		if(record.getValue("custName")!=null&&record.getValue("custName")!=""){
	  			custName =Util.encode(record.getValue("custName"));
	  		}
	  		var orgName = "";
	  		if(record.getValue("orgName")!=null&&record.getValue("orgName")!=""){
	  			orgName =Util.encode(record.getValue("orgName"));
	  		}
	  		var urlParas = "?custId=" + custId + "&orgId=" + orgId+"&custName="+custName+"&orgName="+orgName;
	  		var url="/jsp/perform/ar/ArDsCust_assign.jsp";
			parent.TabUtil.openTab('dsCust', '对公客户分配明细', url + urlParas, true);
		}
		//选择部门
		function LookupDropDown_Org_onSelect(dropdown,iframe,text){
			
			var dataset = $J(iframe.Dataset_Org);
			
			var node = $J(iframe.DataTree_Org).getCurrentNode();
			    var record = dataset.getCurrentRecord();
			    if(typeof record != "undefined" && record != null){
			    	//alert(record.getValue("name"));
			    	$J("orgId").setValue(record.getValue("orgId"),record.getValue("orgName"));
			    }
		}
	</script>
</html>